<template>
	<view class="community">
		<view class="head_bg"></view>
		<view class="big_box">
			<view class="count_tab">
				<view :class="{count_tab_inner: istrue == true,is_active: tabIndex == 1}" @tap="tabSelect" :data-id="1" style="margin-left: 145rpx;">日报表</view>
				<view :class="{count_tab_inner: istrue == true,is_active: tabIndex == 2}" @tap="tabSelect" :data-id="2" style="margin-right: 145rpx;">月报表</view>
			</view>
			<view v-if="tabIndex == 1">
				<view class="operating_box" v-for="(info1,index) in list" :key="index" style="margin-top:20rpx;" v-if="tabIndex == 1">
					<view class="count_title_box">
						<text class="count_title">{{info1.settlement_time}}</text>
					</view>
					<view class="count_inner">
						<view class="count_line">
							<view class="count_line_left">收入： </view>
							<view class="count_line_right">{{info1.settlement_amount}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">订单：</view>
							<view class="count_line_right"> {{info1.order_num}}次</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">套餐： </view>
							<view class="count_line_right"> {{info1.set_meal_income}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">电费： </view>
							<view class="count_line_right"> {{info1.order_electricity_fees}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">电量： </view>
							<view class="count_line_right"> {{info1.power_consumption}}度</view>
						</view>
					</view>
					<view class="count_bottom">
						<view class="count_bottom_inner">分成：
						<text class="count_bottom_inner_1">￥</text>
						<text class="count_bottom_inner_2">{{info1.settlement_amount}}元</text>
						</view>
					  
					</view>
				</view>
				<view style="height:100rpx;"></view>
				<view v-if="list.length==0" class="margin-top-lg text-center">
					<image src='../../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
				</view>
				<!-- <view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
					{{loadingTxt}} 共({{list.length}}条记录)
				</view> -->
			</view>
			<view v-if="tabIndex == 2">
				<view class="operating_box" v-for="(info1,index) in list" :key="index" style="margin-top: 20rpx;">
					<view class="count_title_box">
						<text class="count_title">{{info1.settlement_month}}</text>
					</view>
					<view class="count_inner">
						<view class="count_line">
							<view class="count_line_left">收入： </view>
							<view class="count_line_right">{{info1.settlement_amount}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">订单：</view>
							<view class="count_line_right"> {{info1.order_num}}次</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">套餐： </view>
							<view class="count_line_right"> {{info1.set_meal_income}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">电费： </view>
							<view class="count_line_right"> {{info1.order_electricity_fees}}元</view>
						</view>
						<view class="count_line">
							<view class="count_line_left">电量： </view>
							<view class="count_line_right"> {{info1.power_consumption}}度</view>
						</view>
					</view>
					<view class="count_bottom">
						<view class="count_bottom_inner">分成：
						<text class="count_bottom_inner_1">￥</text>
						<text class="count_bottom_inner_2">{{info1.settlement_amount}}元</text>
						</view>
					</view>
				</view>
				<view style="height:100rpx;"></view>
				<view v-if="list.length==0" class="margin-top-lg text-center">
					<image src='../../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
				</view>
				<!-- <view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
					{{loadingTxt}} 共({{list.length}}条记录)
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				tabIndex: 1,
				istrue: true,
				list:[],
			}
		},
		onLoad(options) {
		},
		onShow() {
			page=1;
			this.list=[];
			this.getlist();
		},
		methods: {
			tabSelect(e) {
				page=1;
				// this.loadingTxt="加载更多";
				this.list=[];
				this.tabIndex = e.currentTarget.dataset.id;
				this.getlist();
			},
			getlist(){
				let that=this;
				let url;
				if(this.tabIndex==1){
					url="agent/v1/daystatistics";
				}else if(this.tabIndex==2){
					url="agent/v1/monthstatistics";
				}
				that.http.tokenreq({
					url: url,
					data:{
						'pageindex':page
					}
				}).then((res) => {
					let e=res.data;
					console.log(e)
					if(e.code==0 && e.success){
						that.list=e.rows;
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			getmorelist(){
				// this.loadingTxt='加载中'
				let that=this;
				let url;
				if(this.tabIndex==1){
					url="agent/v1/daystatistics";
				}else if(this.tabIndex==2){
					url="agent/v1/monthstatistics";
				}
				that.http.tokenreq({
					url: url,
					data:{
						'pageindex':page
					}
				}).then((res) => {
					uni.hideLoading();
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							// that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
			},
		}
	}
</script>
<style>
	.head_bg {height:80rpx;}
	.operating_box{
		padding-bottom: 0;
	}
	.count_bottom_inner{
		line-height: 60rpx;
	}
</style>
